package member;

import java.util.ArrayList;
import java.sql.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import common.misc.StringMisc;

public class MemberInsertCommand implements MemberCommand {

	public void execute(HttpServletRequest request, HttpServletResponse response) throws  MemberException, SQLException {
			
		String id = StringMisc.fixNull(request.getParameter("id"));
		
		String pw = StringMisc.fixNull(request.getParameter("pw"));
		
		String name = StringMisc.fixNull(request.getParameter("name"));
		
		String zipcode1 = StringMisc.fixNull(request.getParameter("zipcode1"));
		String zipcode2 = StringMisc.fixNull(request.getParameter("zipcode2"));
		String zipcode = zipcode1+zipcode2;
		
		String addr1 = StringMisc.fixNull(request.getParameter("addr1"));
		String addr2 = StringMisc.fixNull(request.getParameter("addr2"));
		String addr = addr1 + addr2;
		
		String birth1 = StringMisc.fixNull(request.getParameter("birth1"));
		String birth2 = StringMisc.fixNull(request.getParameter("birth2"));
		String birth3 = StringMisc.fixNull(request.getParameter("birth3"));
		String birth = birth1+birth2+birth3;
		
		String gender = StringMisc.fixNull(request.getParameter("gender"));
		
		String hp1 = StringMisc.fixNull(request.getParameter("hp1"));
		String hp2 = StringMisc.fixNull(request.getParameter("hp2"));
		String hp3 = StringMisc.fixNull(request.getParameter("hp3"));
		String hp = hp1+hp2+hp3;
		
		String emaill = StringMisc.fixNull(request.getParameter("email1"));
		String email2 = StringMisc.fixNull(request.getParameter("email2"));
		String email = emaill+"@"+email2;
		
		System.out.println("test");
		
		MemberTO memlist = new MemberTO();
		memlist.setId(id);
		memlist.setPw(pw);
		memlist.setName(name);
		memlist.setZipcode(zipcode);
		memlist.setAddr(addr);
		memlist.setEmail(email);
		memlist.setBirth(birth);
		memlist.setGender(gender);
		memlist.setHp(hp);		
		memlist.setEmail(email);
				
		MemberControl membercontrol = new MemberControl();
		try{
			membercontrol.memInsert(memlist);
				
		}catch(SQLException sqle){
			throw sqle;
		}		
	}
}